package particlesystem.effects {
	import particlesystem.core.ParticleData;
	import particlesystem.utils.Range;

	/**
	 * @author robertthurston
	 */
	public class LifeEffect implements IEffect {

		private var life : Range;
		private var alphaFadeLevels : int;

		public function LifeEffect(minLife : Number, maxLife : Number, alphaFadeLevels : int) {
			life = new Range(minLife, maxLife);
			
			this.alphaFadeLevels = alphaFadeLevels;
		}

		public function reset(particleData : ParticleData) : void {
			particleData.life = life.range;
			particleData.life += alphaFadeLevels;
			particleData.alphaFade = 1;
		}

		public function update(particleData : ParticleData) : void {
			particleData.life--;

			if(particleData.life < alphaFadeLevels) {
				particleData.alphaFade = particleData.life / alphaFadeLevels;
			}
			
		}
	}
}
